import { get, post, put, del } from '@/utils/request'

// 订单相关的类型定义
export interface Order {
  orderId?: string
  ordercode?: string
  comFrom?: string
  userName?: string
  phone?: string
  inTime?: string
  outTime?: string
  desc?: string
  money?: number
  roomCode?: string
  userId: string
  orderState?: number
  orderStateName?: string
}

export interface OrderQueryParams {
  pageIndex?: number
  pageSize?: number
  orderCode?: string
  userName?: string
  orderState?: number
  sDate?: string
  eDate?: string
}

export interface OrderResponse {
  totalCount: number
  totalPages: number
  list: Order[]
}

// API 响应类型
export interface ApiResponse<T> {
  code: number
  msg: string
  data: T
}

// 创建订单的参数类型
export interface CreateOrderParams {
  orderId?: string
  ordercode?: string
  comFrom?: string
  userName?: string
  phone?: string
  inTime?: string
  outTime?: string
  desc?: string
  money?: number
  roomCode?: string
  userId: string
  orderState?: number
  orderStateName?: string
}

export interface OrderState {
  name: string
  value: number
}

// 获取订单状态列表
export const reqOrderStateList = () => {
  return get<ApiResponse<OrderState[]>>('/api/OrderMessages/GetOrderStateList')
}
// 获取订单列表
export const reqOrderList = (data: OrderQueryParams) => {
  return get<ApiResponse<Order[]>>('/api/OrderMessages/GetOrderList', data)
}

// 修改订单状态
export const reqUpdateState = (id: number, state: number) => {
  return put<ApiResponse<number>>(
    `/api/OrderMessages/UpdateStateOrder?orderId=${id}&state=${state}`
  )
}

// 订单统计列表
export const reqOrderStateCount = (data?: any) => {
  return get<ApiResponse<any>>(`/api/OrderMessages/GetOrderCount`, data)
}
